package jeconbond.automata.behaviour.antstrat;

import java.util.Arrays;

import laboratoryQ.BaseUtils;

public class FeramonNote {
	/**
	 * position 2 write.
	 */
	public int position = 0;
	static { System.out.println("\nSMALL AFTER_ANT_ALIVE compute as geometry progress"); }
	public double[] feramonHistory;
	public FeramonNote(int feramonHistoryLength) {
		this.feramonHistory = new double[feramonHistoryLength];
		Arrays.fill(feramonHistory, 0.0);
	}
	
	public void storeFeramon(double feramonValue) {
		int length = feramonHistory.length;
		feramonHistory[position] = feramonValue;
		position = BaseUtils.cycleNext(position, length);
	}
	
	public double computeFeramon() {
		double result = 1.0;
		int length = feramonHistory.length;
		double mul = 1.0;
		for (int i = position;;) {
			i = BaseUtils.cyclePrev(i, length);
			result += feramonHistory[i] * mul;
			mul /= 2.0;
			if (i == position) {
				break;
			}
		}
		return result;
	}
}
